package com.rainng.coursesystem.service;

import com.rainng.coursesystem.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommentService {

    @Autowired
    private CommentRepository commentRepository;

    // 获取指定帖子下的所有评论
    public List<Map<String, Object>> getCommentsByPostId(int postId) {
        return commentRepository.findByPostId(postId);
    }

    // 新增评论
    public String addComment(int postId, int studentId, String content) {
        int rowsAffected = commentRepository.addComment(postId, studentId, content);
        return rowsAffected > 0 ? "评论添加成功" : "评论添加失败";
    }

    // 删除评论
    public String deleteComment(int commentId) {
        int rowsAffected = commentRepository.deleteComment(commentId);
        return rowsAffected > 0 ? "评论已删除" : "评论删除失败";
    }
}

